package com.test.dag;

import java.util.List;

/**
 * GPT学习实现：Java实现带有条件分支的DAG有向无环图的拓扑排序
 * https://chatgpt.com/c/676fb01d-6d48-8010-96f6-09a3ffc85ea3
 *
 * @author yulongtian
 * @create 2024-12-28 16:06
 */
public class TopologicalSortWithConditionalBranches {
    public static void main(String[] args) {
        DirectedGraph graph = new DirectedGraph();

        // 添加边（带有条件分支的DAG）
        graph.addEdge(0, 1);  // 0 -> 1
        graph.addEdge(0, 2);  // 0 -> 2
        graph.addEdge(1, 3);  // 1 -> 3
        graph.addEdge(2, 3);  // 2 -> 3
        graph.addEdge(3, 4);  // 3 -> 4

        // 进行拓扑排序
        List<Integer> sortedOrder = graph.topologicalSort();

        // 输出结果
        if (!sortedOrder.isEmpty()) {
            System.out.println("拓扑排序结果: " + sortedOrder);
        }
    }
}
